<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>函数节流</title>
</head>
<body>
    
</body>
</html>
<script>
    var throttle = function(fn,interval){
        var _self = fn,
            timer,
            firstTime = true;

        return function(){
            var args = arguments,
            _me = this;

            if(firstTime){
                _self.apply(_me,args);
                return firstTime = false;
            }

            if(timer){
                return false;
            }
            timer = setTimeout(function(){
                // debugger;
                clearTimeout(timer);
                timer = null;
                _self.apply(_me,args);
            },interval ||500);

        }

    }

    window.onresize = throttle(function(){
        console.log(Date.now());
    },500)
</script>